<?php


namespace app\system\service;

class DataService
{
	public static function getHourDate($type)
	{
		$dates = [];
		$names = [];
		for ($i = 0; $i <= 23; $i++) {
			$hour = $i >= 10 ? $i : "0" . $i;
			$dates[] = $i;
			$names[] = $i . "时~" . ($i + 1) . "时";
		}
		if ($type == true) {
			return $names;
		} else {
			return $dates;
		}
	}
	public static function getHourData($sid, $days, $type, $others_1 = false)
	{
		$date = date("Ymd", $days);
		for ($i = 0; $i <= 23; $i++) {
			$hour = $i >= 10 ? $i : "0" . $i;
			$data[] = \intval(\app\common\server\StatisticsData::get($sid, $type, "YmdH", $date . $hour, 0, $others_1));
		}
		return $data;
	}
	public static function getDayDate($days, $num, $type)
	{
		$dates = [];
		$names = [];
		for ($i = 0; $i <= $num; $i++) {
			$day = date("d", strtotime(date("Y-m-d H:i:s", $days) . " - {$i} days"));
			$dates[] = $day;
			$names[] = $day . "日";
		}
		$dates = array_reverse($dates);
		$names = array_reverse($names);
		if ($type) {
			return $names;
		} else {
			return $dates;
		}
	}
	public static function getDayData($sid, $days, $num, $type, $others_1 = false)
	{
		for ($i = 0; $i <= $num; $i++) {
			$day = date("Ymd", strtotime(date("Y-m-d H:i:s", $days) . " - {$i} days"));
			$data[] = \intval(\app\common\server\StatisticsData::get($sid, $type, "Ymd", $day, 0, $others_1));
		}
		$data = array_reverse($data);
		return $data;
	}
}